#import stackless
import socket
import struct
#import server
#import world
import sys
import os

import time

def gs_test(port):
    channel = stackless.channel()
    #gs = server.GameServer(socket.SOCK_DGRAM, 'localhost', 45987, {"localhost": channel})
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    #print sock.sendto(struct.pack("B", 0), ('localhost', 45987))
    #print sock2.sendto(struct.pack("B", 1), ('localhost', 45987))
    sock.connect(('localhost', 45988))
    print sock.sendall(struct.pack("B24s", 0, 'hello world!hello world!'))
    #time.sleep(1)
    print sock2.sendto(struct.pack("B24s", 1, 'This is sock2...........'), ('127.0.0.1', 45988))
    sock.close()

def stress_test(port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.connect(('localhost', port))
    if sys.argv[1] != 'AAARRRGGHH!!! Ive been spawned!':
        os.system("python /home/adam/Programming/Space_Game/drafts/server_tests.py 'AAARRRGGHH!!! Ive been spawned!'")
    for i in xrange(1000000):
        sock.sendall(sys.argv[1])

if __name__ == "__main__":
    #gs_test(45988)
    stress_test(45988)
